unit ufTask_Property_Errors;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ufTask_Property_ActionCustom, Vcl.Mask, Vcl.StdCtrls, Vcl.ExtCtrls,
  uformDataModule, uTasks;

type
  TTfTask_Property_Errors = class(TTfTask_Property_ActionCustom)
    pExtendedErrorExecutionParams: TPanel;
    Label5: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label13: TLabel;
    eRepeatActionCount: TEdit;
    eRepeatInterval: TMaskEdit;
    eRepeatIntervalIncrement: TMaskEdit;
    eActionDurationTime: TMaskEdit;
    rbBreakOnError: TRadioButton;
    rbContinueOnError: TRadioButton;
    rbTryExecute: TRadioButton;
    cbUnlimit: TCheckBox;
    lActionDurationTime: TLabel;
    shBackground: TShape;
    procedure cbUnlimitClick(Sender: TObject);
    procedure rbBreakOnErrorClick(Sender: TObject);
  private
    { Private declarations }
  public
    procedure Prepare(AStep: TStep); override;
    procedure SaveChanges;
  end;

var
  TfTask_Property_Errors: TTfTask_Property_Errors;

implementation

{$R *.dfm}


{ TTfTask_Property_Errors }

procedure TTfTask_Property_Errors.cbUnlimitClick(Sender: TObject);
begin
  lActionDurationTime.Visible:= not cbUnlimit.Checked;
  eActionDurationTime.Visible:= not cbUnlimit.Checked;
  if cbUnlimit.Checked then
    shBackground.Height:= 108
  else
    shBackground.Height:= 132
end;

procedure TTfTask_Property_Errors.Prepare(AStep: TStep);
begin
  inherited;
  if AStep.BreakTaskIfErrorInStep then
    rbBreakOnError.Checked:= True
  else if AStep.IgnoreErrorAndGotoNextStep then
    rbContinueOnError.Checked:= True
  else
    rbTryExecute.Checked:= True;

  eRepeatActionCount.Text:= IntToStr(AStep.RepeatActionCount);
  eRepeatInterval.Text:= ConvertSecondsInText(AStep.RepeatInterval);
  eRepeatIntervalIncrement.Text:= ConvertSecondsInText(AStep.RepeatIntervalIncrement);

  cbUnlimit.Checked:= AStep.ActionDurationTime = 0;
  eActionDurationTime.Text:= ConvertSecondsInText(AStep.ActionDurationTime);

  rbBreakOnErrorClick(nil);
  cbUnlimitClick(nil);
end;

procedure TTfTask_Property_Errors.rbBreakOnErrorClick(Sender: TObject);
begin
  pExtendedErrorExecutionParams.Visible:= rbTryExecute.Checked;
end;

procedure TTfTask_Property_Errors.SaveChanges;
begin
  FStep.BreakTaskIfErrorInStep:= rbBreakOnError.Checked;
  FStep.IgnoreErrorAndGotoNextStep:= rbContinueOnError.Checked;

  FStep.RepeatActionCount:= StrToInt(eRepeatActionCount.Text);
  FStep.RepeatInterval:= ConvertTextInSecond(eRepeatInterval.Text);
  FStep.RepeatIntervalIncrement:= ConvertTextInSecond(eRepeatIntervalIncrement.Text);
  if cbUnlimit.Checked then
    FStep.ActionDurationTime:= 0
  else
    FStep.ActionDurationTime:= ConvertTextInSecond(eActionDurationTime.Text);
end;

end.
